<input hidden="hidden" id="navValue" value="股东列表">
<div class="page-content">
    <div class="page-header">
        <h1>
            股东管理
            <small>
                <i class="ace-icon fa fa-angle-double-right"></i>
                添加股东
            </small>
        </h1>
    </div><!-- /.page-header -->

    <div class="row">
        <from class="form-horizontal" role="form">
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 搜索用户: </label>

                <div class="col-sm-8">
                    <input type="text" id="searchPhone" placeholder="手机号" class="col-xs-10 col-sm-5" style="margin-right: 30px;"  value={:input('get.phone')}>
                    <button id="searchBtn" type="submit" class="dt-button buttons-collection buttons-colvis btn btn-white btn-primary btn-bold" tabindex="0" aria-controls="dynamic-table" data-original-title="" title="搜索"><span><i class="fa fa-search bigger-110 blue"></i></span></button>
                </div>
            </div>
        </from>

        <form class="form-horizontal user-data" role="form" style="display: none;" action="{:url('insert')}" method="get">
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 用户名: </label>

                <div class="col-sm-5">
                     <input type="text" id="realname" placeholder="用户名" class="col-xs-10 col-sm-5" value="张三" readonly='readonly'>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 电话: </label>

                <div class="col-sm-5">
                    <input type="text" id="phone" name="phone"placeholder="手机号" class="col-xs-10 col-sm-5" value="1354545445" readonly="readonly">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 积分: </label>

                <div class="col-sm-5">
                    <input type="text" id="score" placeholder="积分" class="col-xs-10 col-sm-5" value="1000" readonly="readonly">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 积分宝: </label>

                <div class="col-sm-5">
                    <input type="text" id="scores" placeholder="积分宝" class="col-xs-10 col-sm-5" value="10000" readonly="readonly">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 封顶积分: </label>

                <div class="col-sm-5">
                    <input type="text" id="scores-limit" placeholder="封顶积分" class="col-xs-10 col-sm-5" value="10001" readonly="readonly">
                </div>
            </div>

            <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 初始股份: </label>

                <div class="col-sm-5">
                    <input type="text" id="shares" name="shares" placeholder="初始股份" class="col-xs-10 col-sm-5" value="0" >
                </div>
            </div>

            <div class="col-md-offset-3 col-md-9" id="submitBtn">
                <button type="submit" class="btn btn-info" type="button">
                    <i class="ace-icon fa fa-check bigger-110"></i>
                    确认新增
                </button>
            </div>
        </form>
        <div class="center form-horizontal col-md-offset-3 col-md-9" id="tips" style="display: none;color: red;">

        </div>

    </div><!-- /.row -->
</div>

<script>
    $("#searchBtn").click(function () {
        $('.user-data').hide();
        $('#tips').hide();
        var phone = $('#searchPhone').val();
        if(phone == ''){
            alert('请输入手机号');
        }else{
            if(!/^[1][0-9]{10}$/.test(phone)){
                alert('请输入正确手机号');
            }else{
                $.ajax({
                    url: "{:url('getUser')}",              //请求地址
                    type: "get",                       //请求方式
                    data: { phone: phone},        //请求参数
                    dataType: "json",
                    success: function (result) {
                        console.log(result);
                        if(result['tag'] == 1){
                            $('#realname').val(result['member']['realname']);
                            $('#phone').val(phone);
                            $('#score').val(result['member']['credit1']);
                            $('#scores').val(result['member']['credit3']);
                            $('#scores-limit').val(result['member']['jifenbao_limit']);
                            $('.user-data').show();
                        }else if(result['tag'] == 2) {
                            $('#realname').val(result['member']['realname']);
                            $('#phone').val(phone);
                            $('#score').val(result['member']['credit1']);
                            $('#scores').val(result['member']['credit3']);
                            $('#scores-limit').val(result['member']['jifenbao_limit']);
                            $('#shares').val(result['shareholder']['shares']).attr('readonly','readonly');
                            $('#submitBtn').css('display','none');
                            $('.user-data').show();
                            $('#tips').html('该会员已经是股东').show();
                        }else{
                            $('.user-data').hide();
                            $('#tips').html('没有该用户').show();
                        }
                    },
                    fail: function (status) {
                        $('#tips').html('没有该用户').show();
                    }
                });
            }
        }
    })
</script>
